package dfbz.com.service.impl;

import dfbz.com.dao.ArticleDao;
import dfbz.com.dao.FavoriteDao;
import dfbz.com.service.ArticleService;

import java.util.List;
import java.util.Map;

public class ArticleServiceImpl implements ArticleService {
                  private ArticleDao articleDao=new ArticleDao();
                  private FavoriteDao favoriteDao=new FavoriteDao();


    public List<Map<String, Object>> findList(Integer userId, int page, String search) {
        List<Map<String, Object>> list = articleDao.findList(userId,page,search);
        return list;


    }


    public long findTotalArticleCount() {
        return articleDao.getTotalArticle();
    }

    public boolean add(String username,Integer uid,String title,String content,String pdate){
        return articleDao.addArticle(username,uid,title,content,pdate);
    }

    public  Map<String, Object> findById(Integer id){
        return  articleDao.findById(id);
    }

    @Override
    public void addFavorite(int aId, int mId) {
        if (!favoriteDao.isExist(aId,mId)){
            favoriteDao.addFavorite(aId,mId);
        }

    }

    @Override
    public List<Map<String, Object>> myCollect(int myId,Integer page,String search) {
        return articleDao.myCollect(myId,page,search);
    }

    @Override
    public Integer findTotalCollects(Object aId) {
        return favoriteDao.findTotalCollects(aId);
    }

    @Override
    public void remove(Integer aId, int userId) {
        articleDao.remove(aId,userId);
    }

    @Override
    public List<Map<String, Object>> findFavoriteCountList() {
        return favoriteDao.findFavoriteCountList();
    }

    @Override
    public void addBrowseCount(Integer id) {
        articleDao.addBrowseCount(id);
    }

    @Override
    public long findMyFavoriteArticleCount(Integer userId) {
        return favoriteDao.findMyFavoriteArticleCount(userId);
    }

    @Override
    public void removeFavorite(int aId, int uId) {
        favoriteDao.removeFavorite(aId,uId);
    }


}
